package com.example.newdemo.net.model;

import android.util.Log;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;

public class HttpSetting {


    private HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
        @Override
        public void log(String message) {
            Log.d("logInterceptor", message);
        }
    });


    /**
     * 创建一个OkHttpClient代理对象，(没有进行build())
     */
    private OkHttpClient.Builder getDefaultOkHttpBuilder() {
        logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        return new OkHttpClient.Builder()
                .readTimeout(30, TimeUnit.SECONDS)// connect timeout
                .connectTimeout(30, TimeUnit.SECONDS)// socket timeout
                .addNetworkInterceptor(logInterceptor)
                .retryOnConnectionFailure(true);
    }

    /**
     * 创建一个OkHttpClient代理对象，(已经进行build())
     */
    public OkHttpClient getDefaultOkHttpClient() {
        return getDefaultOkHttpBuilder().build();
    }


}
